﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Marbles.Core.Connectors;

namespace Marbles.Core.BBS
{
    public class ForumCategoryCollection : ICollection<ForumCategory>
    {
        public ForumCategory this[int index] { get { return items[index]; } }
        public Int32 Count { get { return items.Count; } }

        private List<ForumCategory> items = null;

        public ForumCategoryCollection(string siteid)
        {
            DataConnection dbc = new DataConnection();
            items = new List<ForumCategory>();
            Command cmd = new Command("SELECT siteid, category, title FROM forumcategory WHERE siteid = @siteid ORDER BY title ASC");
            cmd.AddParameter("@siteid", siteid);
            foreach (DataRow dr in dbc.FetchDataTable(cmd).Rows)
            {
                items.Add(new ForumCategory(dr));
            }
        }

        public void Add(ForumCategory item)
        {
            items.Add(item);
        }

        public void Clear()
        {
            items.Clear();
        }

        public bool Contains(ForumCategory item)
        {
            return items.Contains(item);
        }

        public void CopyTo(ForumCategory[] array, int arrayIndex)
        {
            items.CopyTo(array, arrayIndex);
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool Remove(ForumCategory item)
        {
            return items.Remove(item);
        }

        public IEnumerator<ForumCategory> GetEnumerator()
        {
            return items.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return items.GetEnumerator();
        }
    }
}
